use crate::data::ParamObject;

pub struct DbTool;

impl DbTool {
    pub fn get_dba_object(param_obj: &ParamObject, table_name: &str) -> String {
        let db_owner = param_obj.get_value_by_env_name("dbOwner");
        if db_owner.is_empty() {
            // TODO: get db_owner from default db_tool
        }

        if db_owner.is_empty() {
            // TODO: get postfix from default db_tool
            let postfix = "";
            format!("{}{}", table_name, postfix)
        } else {
            todo!()
        }
    }

    pub fn select_sql(table_name: &str, fields: &str, where_: &str, orderby: &str) -> String {
        match (where_.is_empty(), orderby.is_empty()) {
            (true, true) => format!(
                "select {} from {} where {} order by {} ",
                fields, table_name, where_, orderby,
            ),
            (true, false) => format!("select {} from {} where {} ", fields, table_name, where_),
            (false, true) => format!("select {} from {} order by {}", fields, table_name, orderby),
            (false, false) => format!("select {} from {} ", fields, table_name),
        }
    }
}
